<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>任务 #{{ task.id }} 状态</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background-color: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            text-align: center;
        }
        .task-info {
            background-color: #e9ecef;
            padding: 15px;
            border-radius: 5px;
            margin-bottom: 20px;
        }
        .status-pending {
            background-color: #fff3cd;
            color: #856404;
            padding: 10px;
            border-radius: 5px;
            text-align: center;
            margin-bottom: 20px;
        }
        .status-running {
            background-color: #cce5ff;
            color: #004085;
            padding: 10px;
            border-radius: 5px;
            text-align: center;
            margin-bottom: 20px;
        }
        .status-completed {
            background-color: #d4edda;
            color: #155724;
            padding: 10px;
            border-radius: 5px;
            text-align: center;
            margin-bottom: 20px;
        }
        .status-failed {
            background-color: #f8d7da;
            color: #721c24;
            padding: 10px;
            border-radius: 5px;
            text-align: center;
            margin-bottom: 20px;
        }
        .log-container {
            background-color: #f8f9fa;
            border: 1px solid #dee2e6;
            border-radius: 5px;
            padding: 15px;
            height: 400px;
            overflow-y: auto;
            font-family: monospace;
            white-space: pre-wrap;
            font-size: 12px;
        }
        .nav-links {
            text-align: center;
            margin-top: 20px;
        }
        .nav-links a {
            display: inline-block;
            margin: 0 10px;
            color: #007bff;
            text-decoration: none;
        }
        .nav-links a:hover {
            text-decoration: underline;
        }
        button {
            background-color: #007bff;
            color: white;
            padding: 10px 15px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
        }
        button:hover {
            background-color: #0056b3;
        }
        .controls {
            margin-bottom: 10px;
            text-align: right;
        }
        .controls button {
            padding: 5px 10px;
            font-size: 12px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>任务 #{{ task.id }} 状态</h1>
        
        <div class="task-info">
            <p><strong>图片目录:</strong> {{ task.images_dir }}</p>
            <p><strong>音频目录:</strong> {{ task.audios_dir }}</p>
            <p><strong>输出目录:</strong> {{ task.output_dir }}</p>
            <p><strong>生成方式:</strong> 
                {% if task.generation_type == 'ai' %}
                    AI生成 (使用DashScope图片转视频)
                {% else %}
                    传统方式 (使用FFmpeg直接生成)
                {% endif %}
            </p>
        </div>
        
        <div class="status-{{ task.status }}">
            <strong>状态:</strong> {{ task.message }}
        </div>
        
        <div class="controls">
            <button onclick="clearLog()">清空日志</button>
            <button onclick="location.reload()">刷新状态</button>
        </div>
        
        <h3>执行日志:</h3>
        <div class="log-container" id="logContainer">{{ task.log }}</div>
        
        <div class="nav-links">
            <a href="{{ url_for('index') }}">返回首页</a>
            <a href="{{ url_for('task_list') }}">查看所有任务</a>
        </div>
    </div>
    
    <script>
        // 如果任务仍在运行，定期刷新日志
        const status = "{{ task.status }}";
        if (status === "pending" || status === "running") {
            setTimeout(function(){
                location.reload();
            }, 3000);
        }
        
        // 滚动到底部
        const logContainer = document.getElementById('logContainer');
        logContainer.scrollTop = logContainer.scrollHeight;
        
        // 清空日志功能
        function clearLog() {
            document.getElementById('logContainer').textContent = '';
        }
    </script>
</body>
</html>